﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using Agnes.Core;

namespace Agnes.TaskManager
{
    public class OpenMonthlyViewCmd
    {
        private static OpenMonthlyViewCmd _instance;

        /// <summary>
        /// 返回唯一实例
        /// </summary>
        public static OpenMonthlyViewCmd Instance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new OpenMonthlyViewCmd();
                }
                return _instance;
            }
        }

        private RoutedCommand _requery;

        /// <summary>
        /// 是否能执行
        /// </summary>
        public bool CanExcuted { get; set; }

        OpenMonthlyViewCmd()
        {
            CanExcuted = false;
            _requery = new RoutedCommand("Task Calendar View Cmd", typeof(OpenMonthlyViewCmd));
        }

        /// <summary>
        /// 浏览文章的路由命令
        /// </summary>
        public static RoutedCommand Requery
        {
            get
            {
                return Instance._requery;
            }
        }

        /// <summary>
        /// 浏览文章执行代码
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void Excuted(object sender, ExecutedRoutedEventArgs e)
        {
            try
            {
                (TaskManagerService.TaskCalendarViewModel.Content as TaskCalendarView).SchedulerControl.ActiveViewType
                    = DevExpress.XtraScheduler.SchedulerViewType.Month;
                if (AgnesServiceManager.AgnesWorkBenchService.DocumentPanels.IndexOf(
                    TaskManagerService.TaskCalendarViewModel) == -1)
                {
                    AgnesServiceManager.AgnesWorkBenchService.DocumentPanels.Add(
                        TaskManagerService.TaskCalendarViewModel);
                }
                else
                {
                    AgnesServiceManager.AgnesWorkBenchService.FocusedDocumentPanel = TaskManagerService.TaskCalendarViewModel;
                }
            }
            catch (Exception ex)
            {
                AgnesServiceManager.LogServ.Error("TaskManager--打开日视图错误；" + ex.Message);
            }
        }

        /// <summary>
        /// 判断是否能执行
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void CanExcute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (AgnesServiceManager.AgnesSlnService.CurrentSln == null)
            {
                e.CanExecute = false;
            }
            else
            {
                e.CanExecute = true;
            }
        }
    }
}
